package com.putable.nmc.world;

import java.io.IOException;
import java.io.Writer;
import java.util.EnumSet;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * The types of tasks that customers to the DMV may wish to perform, as seen by
 * the DMV.
 * 
 * @author ackley
 * 
 */
public enum Task {
    /**
     * The least revenue-generating sort of task. 
     */
    CHEAP, 
    /**
     * A typically revenue-generating sort of task.
     */
    AVERAGE, 
    /**
     * The most revenue-generating sort of task.
     */
    EXPENSIVE;
    
    private int cost;

    /**
     * Access the revenue of this task type.
     * 
     * @return the cost
     */
    public int getCost() {
        return cost;
    }

    /**
     * Write the task costs of all tasks to a Writer, in a format
     * readable by {@link #readCosts(Scanner)}.
     * 
     * @param w Writer to write to
     * @throws IOException if an IO problem occurs
     */
    public static void writeCosts(Writer w) throws IOException {
        boolean first = true;
        for (Task t : EnumSet.allOf(Task.class)) {
            if (first)
                first = false;
            else
                w.write(" ");
            w.write(t.cost + "");
        }
        w.write("\tTask Costs\n");
    }

    /** 
     * Initialize the costs of all types of tasks by reading from a Scanner,
     * accepting as input the form produced by {@link #writeCosts(Writer)}.
     * 
     * @param sc The Scanner to read from
     * @throws InputMismatchException  if any illegal format is detected
     */
    public static void readCosts(Scanner sc) throws InputMismatchException {
        for (Task t : EnumSet.allOf(Task.class)) {
            t.cost = sc.nextInt();
        }
        sc.nextLine(); // eat rest of line
    }
}

